package com.lordjoe.sudoku;

import java.util.*;

/**
 * com.lordjoe.sudoku.CellMessage
 * Message a cell sends to a constraint
 * User: Steve
 * Date: 4/7/12
 */
public class CellMessage {
    public static final CellMessage[] EMPTY_ARRAY = {};

    private final double[] m_Values = new double[SudokuBoard.getBoardSize()];
    private final SudokuCell m_Cell;

    public CellMessage(final SudokuCell cell, SudokuConstraint cnstr) {
        m_Cell = cell;
        m_Cell.populateCellMessage(this,cnstr);
    }

    public SudokuCell getCell() {
        return m_Cell;
    }

    public String toString() {
        String name = getCell().toString() + ":";
        for (double d : getValues()) {
            name += String.format("%2.1f,", d);
        }
        return name;
    }


    public double[] getValues() {
        return m_Values;
    }

    /**
     * make all values sum to one
     */
    protected void normalize() {
        double sum = 0;
        for (double d : m_Values)
            sum += d;
        if (sum == 0)
            return;
        for (int i = 0; i < m_Values.length; i++) {
            m_Values[i] /= sum;

        }
    }

}
